﻿using System;
using System.Collections.Generic;

namespace Wombat.Common
{
    public static class ObjectExtensions
    {
        public static void NullSafe<TIn>(this TIn obj, Action<TIn> action)
        {
            if (!EqualityComparer<TIn>.Default.Equals(obj, default(TIn)))
                action(obj);
        }

        public static TOut NullSafe<TIn, TOut>(this TIn obj, Func<TIn, TOut> memberAction)
        {
            return (EqualityComparer<TIn>.Default.Equals(obj, default(TIn))) ? default(TOut) : memberAction(obj);
        }
    }
}
